package com.project.nhantvt.SessionBean;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.project.entity.Staff;

/**
 * Session Bean implementation class EmployeeBean
 */
@Stateless
@LocalBean
public class EmployeeBean implements EmployeeBeanRemote {

    /**
     * Default constructor. 
     */
	
	@PersistenceContext
	EntityManager em;
	
    public EmployeeBean() {
        // TODO Auto-generated constructor stub
    }

	@SuppressWarnings("unchecked")
	@Override
	public List<Staff> GetAllStaff() {
		Query query = em.createQuery("select acc from Staff acc where acc.isAdmin = false");
		
		List<Staff> result = (List<Staff>)query.getResultList();
		
		return result;
	}

	@Override
	public boolean InsertStaff(Staff staff) {
		em.persist(staff);
		return true;
	}

	@Override
	public boolean UpdateStaff(Staff staff) {
		em.merge(staff);
		return true;
	}

	@Override
	public List CheckEmail(String email) {
		Query query = em.createQuery("select acc from Staff acc where acc.email = :email");
		
		query.setParameter("email", email);
		List result = query.getResultList();
		
		return result;
	}

}
